import axios from "axios";
import {_getStorage} from "@/utils/localStorage.js";
//创建axios对象
const instance = axios.create({
  baseURL: '/api',
  timeout: 20000,
  headers: {
    'Content-Type': 'application/json'
  }
});
//请求拦截器
instance.interceptors.request.use(config => {
  if (_getStorage("info")) {
    config.headers["token"] = _getStorage("info").token;
  }
  return config;
}, error => {
  return Promise.reject(error);
});
//响应拦截器
instance.interceptors.response.use(response => {
  const {data} = response
  return data;
}, error =>{
  return Promise.reject(error);
});
export default instance;